﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using jsptpd.Pm.Interface.webServiceReader;
using System.Data;
using Jsptpd.Common.DB;
using Jsptpd.Common.dataInital;

namespace jsptpd.Pm.Interface.Oper
{
    public class DataOperation
    {
        #region Attribute
        private log4net.ILog logger = log4net.LogManager.GetLogger(typeof(DataOperation)); 
        #endregion

        #region Function
        public string GetDocumentSet(bool isFullField)
        {
            DocumentServiceReader dsr = new DocumentServiceReader();
            string sql = DataStructureConstractor.constructSqlString(isFullField);
            string xml = dsr.searchDocumentsBySQLFormat2XML(sql, "11e2-809a-99fe60d6-b96a-59e13d804b12", "gy0160");
            if (xml != null)
            {
                logger.Info("Read the xml result:" + xml);
            }
            else
            {
                logger.Error("The xml result is null.Maybe encount an error!");
            }
            return xml;
        }

        public string ReadDataFromPM(bool isFullField)
        {
            DataOperation dataOper = new DataOperation();
            string xmlstr = dataOper.GetDocumentSet(isFullField);
            if (xmlstr != null)
            {
                logger.Info("Read data success...");
                string fileSavePath = System.IO.Directory.GetCurrentDirectory() + @"\pm.xml";
                System.IO.File.WriteAllText(fileSavePath, xmlstr);
            }
            else
            {
                logger.Error("Read data failed...");
            }
            return xmlstr;
        }


        public void UpdateTableToDB(DataTable dt)
        {
            UpdateOperation updateOperation = new UpdateOperation();
            for (int row = 0; row < dt.Rows.Count; row++)
            {                
                if (dt.Rows[row]["项目编号"].ToString() != "" && dt.Rows[row]["项目名称"].ToString() != "")
                {
                    updateOperation.DataUpdateLogic(dt.Rows[row]);
                }
                else
                {
                    logger.Error("数据行ID为：的项目编号或项目名称为空");
                }
            }
        }


        #endregion
      


      




    }
}
